<!-- <template>
        <div class="login-card">
                <div class="login-title">

                    <Transition name="fade-slide" mode="out-in">
                        <h2 class="title1" :key="role">{{ titleTextStu1 }}</h2>
                    </Transition>

                    <Transition name="fade-slide" mode="out-in">
                        <h2 class="title2" :key="role">{{ titleTextStu2 }}</h2>
                    </Transition>

                </div>

                <div class="login-switch">

                    <button
                    :class="{ active: role === 'student' }"
                    @click="role = 'student'"
                    class="login-switch-btn1"
                    >
                        学生
                    </button>
                    
                    
                    <button
                    :class="{ active: role === 'admin' }"
                    @click="role = 'admin'"
                    class="login-switch-btn2"
                    >
                        管理员
                    </button>
                </div>

            </div>
</template> -->


<template>
    <div class="login-card">
        <!-- 头部标题区域 -->
        <div class="login-title">
            <Transition name="fade-slide" mode="out-in">
                <h2 class="title1" :key="role">{{ titleTextStu1 }}</h2>
            </Transition>
            <Transition name="fade-slide" mode="out-in">
                <h2 class="title2" :key="role">{{ titleTextStu2 }}</h2>
            </Transition>
        </div>

        <div class="login-switch">
            <button
                :class="{ active: role === 'student' }"
                @click="handleRoleChange('student')"
                class="login-switch-btn1"
            >
                学生
            </button>
            <button
                :class="{ active: role === 'admin' }"
                @click="handleRoleChange('admin')"
                class="login-switch-btn2"
            >
                管理员
            </button>
        </div>
    </div>
</template>

<script setup>
import { ref, computed, defineProps, defineEmits } from 'vue'; // 补充导入

// 定义props和emit
const props = defineProps({
    role: {
        type: String,
        required: true
    }
})

const emit = defineEmits(['update:role'])

// 处理角色变更
const handleRoleChange = (newRole) => {
    emit('update:role', newRole)
}

// 计算属性
const titleTextStu1 = computed(() => {
    return props.role === 'student' ? '欢迎报到，' : '欢迎登录，'
})
const titleTextStu2 = computed(() => {
    return props.role === 'student' ? '新同学！' : '管理员！'
})
</script>




<!-- <script setup>
import { ref, computed } from 'vue';

const role = ref('student')


const props = defineProps({
    role: {
        type: String,
        required: true
    }
})

const emit = defineEmits(['update:role'])

// 3、计算属性依赖于现在的props.role
const titleTextStu1 = computed(() => {
    return props.role === 'student' ? '欢迎报到，' : '欢迎登录，'
})
const titleTextStu2 = computed(() => {
    return props.role === 'student' ? '新同学！' : '管理员！'
})

// 4、定义更新角色信息的方法
const updateRole = () => {
    emit('update:role', newRole)
}


</script> -->


<style scoped>

.login-card {
    width: 448px;
    height: 552px;
    background-color: #fff;
    border-radius: 24px;
    display: flex;
    align-items: center;
    flex-direction: column; /* 子元素垂直布局 */
    background-color: var(--bg-color-common);
}

.login-title {
    margin-top: 48px;
    width: 448px;
    height: 134px;
    display: flex;
    /* align-items: center; */
    flex-direction: column;
}

.login-title h2 {
    line-height: 67.2px;
    font-weight: 400;
    font-size: 48px;
    tab-size: 4;
    display: block;
    font-family: copernicus, "copernicus Fallback", Georgia, "Times New Roman", Times, serif;
    font-feature-settings:"liga";
    font-style: italic;
}


.login-title > .title1 {
    margin-left: 30px;
}


.login-title > .title2 {
    text-align: right;
    margin-right: 30px;
}

.login-switch {
    width: 224px;
    height: 44px;
    justify-content: center;
    align-items: center;
    display: flex;
    border-radius: 9.6px;
    border:none;
    background-color: transparent;
    border: 1px solid var(--border-color-common);
    margin-top: 16px;
}

.login-switch button {
    width: 112px;
    height: 100%;
    font-size: 18px;
    font-weight: 400;
    background-color: transparent;
    transition: transform 1s ease, box-shadow 1s ease;
    border: none;
    cursor: pointer;
}





.login-switch-btn1 {
    border-bottom-left-radius: 9.6px;
    border-top-left-radius: 9.6px;
}

.login-switch-btn2 {
    border-bottom-right-radius: 9.6px;
    border-top-right-radius: 9.6px;
}


.login-switch button:hover {
    border: 1px solid var(--border-color-hover);
    border-radius: 9.6px;
}

.login-switch-btn1.active {
    background-color: var(--bg-color-hover);
    border-radius: 9.6px;
}

.login-switch-btn2.active {
    background-color: var(--bg-color-hover);
    border-radius: 9.6px;
}


.fade-slide-enter-active,
.fade-slide-leave-active {
  transition: all 0.18s ease; /* 动画持续 0.4 秒，使用 ease 缓动曲线 */
}

/* 新元素进入动画的起始状态
    - 完全透明
    - 在垂直方向上向下偏移 20px
*/
.fade-slide-enter-from {
    opacity: 0;
    transform: translateY(20px);
}

/* 旧元素离开动画的结束状态
    - 完全透明
    - 在垂直方向上向上偏移 20px
*/
.fade-slide-leave-to {
    opacity: 0;
    transform: translateY(-20px);
}

</style>